/******************************************************************************
* This file is part of is32p218 platform,
* Copyright (c) 2009 HangZhou InfoStrong CO.,LTD. All rights reserved.
* This software may only be used under the terms of a valid, current,
* end user license from InfoStrong.
* Nothing else gives you the right to use this software.   
*
* Name:   drv_uart.h
* Desc:   UART Module driver header file
* Author: Jerry
* Date:   2009-9-15
* Note:   
* History:
*
******************************************************************************/
#include "def.h"
#include "os_api.h"
#include "option.h"

#ifndef __DRV_UART_H__
#define __DRV_UART_H__

#ifdef __cplusplus
extern "C" {
#endif

#define UART_TX_QUE_FLG			0

#define UART_BAUD_600		1249
#define UART_BAUD_1200		624
#define UART_BAUD_2400		312
#define UART_BAUD_4800		155
#define UART_BAUD_9600		77
#define UART_BAUD_19200		38
#define UART_BAUD_38400 	19
#define UART_BAUD_57600		12
#define UART_BAUD_750000	0

//#define DRV_UART_ITEM_SIZE		1
#define DRV_UART_ITEM_SIZE		2
#define DRV_UART_RX_BUFF_LEN	256
#define DRV_UART_TX_BUFF_LEN	256

typedef struct
{
    isOS_QUE m_rx_que;
	U8 m_rx_buff[DRV_UART_RX_BUFF_LEN*DRV_UART_ITEM_SIZE+1];
#if UART_TX_QUE_FLG
	volatile U8 m_tx_int_flg;			// Interrupt Send Flag
	isOS_QUE m_tx_que;
	U8 m_tx_buff[DRV_UART_TX_BUFF_LEN*DRV_UART_ITEM_SIZE+1];
#else
	volatile U8 m_tx_ok_flg;			// TX Send OK flag
#endif
	isOS_SEM m_sem;
	U16 m_baud;
}DrvUARTCtrl;

typedef enum
{
	DRV_UART_QUE_TX,
	DRV_UART_QUE_RX
}DRV_UART_QUE_TYPE;


void drv_uart_init(U16 baud);
void drv_uart_baud_set( U16 baud );
char drv_uart_rec_byte(void);
BOOL drv_uart_send_byte(U8 data);
BOOL drv_uart_send( U8 *p_snd_data, U32 snd_len, BOOL blk_flg );
BOOL drv_uart_send_shift_ok( void );
BOOL drv_uart_send2( U8 *p_snd_data, U32 snd_len, BOOL blk_flg );
isOS_QUE *drv_uart_que_get( DRV_UART_QUE_TYPE mode );
void drv_uart_busy_set( BOOL busy_flg );
void drv_uart_int_init( void );
INT_FUNC isr_uart_rx( void );
INT_FUNC isr_uart_tx(void);
BOOL drv_uart_status_check(void);
void drv_uart_status_reset(void);
BOOL drv_uart_baud_check(void);
void drv_uart_baud_resume(void);
void drv_uart_baud_set(U16 baud);

BOOL drv_uart2_init( U16 baud, S32 offset );
void drv_uart2_check( void );
void drv_uart2_rx_ena( BOOL rx_flg );
U8 drv_uart2_ssr_get( void );
void drv_uart2_ssr_clr( void );

#ifdef __cplusplus
}
#endif

#endif /*__DRV_UART_H__*/

